; (function (window) {
    "use strict";  
    var dataAuthority = {};  
    function initDataAuthority() { 
        frame.ajax({
            url: "/Manage/User/GetUserAuthorizeJson",
            type: "get",
            async: false,
            success: function (obj) {
                if (obj.success) {
                    dataAuthority = obj.data;
                    console.log(dataAuthority)
                }
            }
        });
    }
    function getButtonAuthority(url, buttonList) { 
        var noAuthorize = [];
        if (dataAuthority) {  
            if (dataAuthority.IsSystem == false) { 
                var regex = /(\/[a-zA-Z]+)\/(.*)\//;  //match url like http://localhost:5000/OrganizationManage/User/UserIndex
                var matches = regex.exec(url);
                if (matches && matches.length >= 3) { 
                    var module = matches[1].replace('/', '');
                    var page = matches[2].replace('/', '');
                    buttonList.forEach(function (btn, btnIndex) {
                        var authorize = module.toLowerCase() + ':' + page.toLowerCase() + ':' + btn.toString().replace('btn', '').toLowerCase();
                        var hasAuthority = false; 
                        dataAuthority.ButtonAuthorizes.forEach(function (authority, authorityIndex) {
                            if (authority.Authorize == authorize) {
                                hasAuthority = true;
                                return false;
                            }
                        });

                        if (!hasAuthority) {
                            noAuthorize.push(btn);
                        }
                    });
                }
            }
        }
        return noAuthorize;
    } 
    initDataAuthority(); 
    window.getButtonAuthority = getButtonAuthority;
})(window);